/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author xgzheng
 */
public class Guest implements TableInterface {

    private int gId;
    private String gName;
    private String gPhone;
    private String gAddress;
    private Sell gSell;
    /**
     * 是否存在这样一个人
     */
    private boolean exist;

    public Guest() {
        exist = false;
    }

    public Sell getgSell() {
        return gSell;
    }

    public void setgSell(Sell gSell) {
        this.gSell = gSell;
    }

    public String getgAddress() {
        return gAddress;
    }

    public void setgAddress(String gAddress) {
        this.gAddress = gAddress;
    }

    public int getgId() {
        return gId;
    }

    public void setgId(int gId) {
        this.gId = gId;
    }

    public String getgName() {
        return gName;
    }

    public void setgName(String gName) {
        this.gName = gName;
    }

    public String getgPhone() {
        return gPhone;
    }

    public void setgPhone(String gPhone) {
        this.gPhone = gPhone;
    }

    public void insert(PreparedStatement pstmt) throws SQLException {
        pstmt.setInt(1, gId);
        pstmt.setString(2, gName);
        pstmt.setString(3, gPhone);
        pstmt.setString(4, gAddress);
        pstmt.setInt(5, 0);
        pstmt.executeUpdate();
        pstmt.close();
    }

    public String getTableName() {
        return "GUEST";
    }

    public int getTableColumnCount() {
        return 5;
    }

    /**
     * @return the exist
     */
    public boolean isExist() {
        return exist;
    }

    /**
     * @param exist the exist to set
     */
    private void setExist(boolean exist) {
        this.exist = exist;
    }

    public String getPrimaryKey() {
        return "gid";
    }

    public Guest getObject(ResultSet resultSet) throws SQLException {
//        Guest guest = new Guest();
        setExist(false);
        if (resultSet.next()) {
            setgId(resultSet.getInt("GID"));
            setgName(resultSet.getString("GNAME"));
            setgAddress(resultSet.getString("GADDRESS"));
            setgPhone(resultSet.getString("GPHONE"));
            setExist(true);
        }
        return this;
    }

    @Override
    public String toString() {
        return this.gName;
    }

    public String toDetailString() {
        return "My name is:"
                + this.gName
                + " GPHONE:" + this.gPhone
                + " GADDRESS:" + this.gAddress;
    }
}
